package com.hctforgreen.greenservice.ui.adapter;

import java.util.List;

import android.app.Activity;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.hctforgreen.greenservice.R;
import com.hctforgreen.greenservice.model.AttrEntity;

public class SpinnerAttrsAdapter extends BaseAdapter {

	private Activity mActivity;
	private List<AttrEntity> mEntities;

	public SpinnerAttrsAdapter(Activity activity, List<AttrEntity> data) {
		mActivity = activity;
		mEntities = data;

	}

	@Override
	public int getCount() {
		return mEntities.size();
	}

	@Override
	public Object getItem(int position) {
		return mEntities.get(position);

	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		String sIndustry = mEntities.get(position).name;
		return new MyAdapterView(mActivity, sIndustry);
	}

	class MyAdapterView extends LinearLayout {

		public MyAdapterView(Context context, String sIndustry) {
			super(context);
			this.setOrientation(HORIZONTAL);

			LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
					LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
			params.setMargins(12, 15, 12, 15);

			TextView name = new TextView(context);
			name.setText(sIndustry);
			name.setTextColor(getResources().getColor(R.color.black));
			addView(name, params);

		}

	}

}
